<?php 

	session_start();
	
	// TODO: Konami code easter egg
	// u, u, d, d, l, r, l, r, b, a

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="http://localhost/atbat/html/" />
	<meta charset="utf-8">
	<title>AtBat :: Baseball Scoring and Statistical Analysis</title>
	<meta name="description" content="">
	<meta name="author" content="Sean Mullin, http://parametercontraption.com">
	<!--  Mobile Viewport Fix j.mp/mobileviewport & davidbcalhoun.com/2010/viewport-metatag -->
	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
	<link rel="shortcut icon" href="images/design/favicon.ico">
	<link rel="apple-touch-icon" href="images/design/apple-touch-icon.png">
	<link rel="stylesheet" href="css/screen.css">
	<!-- For the less-enabled mobile browsers like Opera Mini --><link rel="stylesheet" media="all" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css" />
    <script src="js/modernizr-1.5.min.js"></script>
</head>
<body>
	<?php require_once 'include/header.html'; ?>
    <section id="content">
    	<section id="indexCTA">
            <?php if(!isset($_SESSION['atbat']) && !isset($_COOKIE['remember_atbat'])) { ?>
                <article id="signup">
                    <h2>Sign Up</h2>
                    <p>Create a user profile so you can save all your players and games. All you need is an e-mail and a password.</p>
                    <p><a href="signup">Get Started</a></p>
                </article>
            <?php }else{ ?>
            	<!-- TODO: show mini roster or box score of last/current game -->
            <?php } ?>
            <article id="create_players">
                <h2>Create Players</h2>
                <p>Choose from predefined team rosters or create your own. A great way to track your fantasy players!</p>
                <?php if(isset($_SESSION['atbat']) or isset($_COOKIE['remember_atbat'])) { ?>
                	<p><a href="create-player">Create Players</a></p>
                <?php } ?>
            </article>
            <article id="score_games">
                <h2>Score Games</h2>
                <p>Learn the art of scoring a baseball game. Save games you've seen live or on TV in a special format that anyone can learn to read.</p>
                <?php if(isset($_SESSION['atbat']) or isset($_COOKIE['remember_atbat'])) { ?>
                	<p><a href="new-game">Score Games</a></p>
                <?php } ?>
            </article>
         </section>
         <?php if(!isset($_SESSION['atbat']) && !isset($_COOKIE['remember_atbat'])) { ?>
             <form action="login" method="post" id="login">
                <fieldset class="left">
                    <legend>Login</legend>
                    <p><label for="username">Username:</label><input type="text" name="username" id="username" required /></p>
                    <p><label for="password">Password:</label><input type="password" name="password" id="password" required /></p>
                    <p class="checkbox"><input type="checkbox" name="remember" id="remember" value="1" /><label for="remember">Remember Me</label></p>
                    <input type="submit" name="login" value="OK" id="loginSubmit" />
                    <p class="quiet small"><a href="forgot">Forgot</a> your login details?</p>
                </fieldset>
             </form>
         <?php }else{ ?>
         	<!-- TODO: show ad slots and dashboard of most recent activity -->
         <?php } ?>
    </section>
    <?php require_once 'include/footer.html'; ?>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script>
    <script>
    	$(document).ready(function() {
			// login stuff
			$("#login").submit(function() {
				// send request
				var login = $("#loginSubmit").val();
				var username = $("#username").val();
				var password = $("#password").val();
				var checked = $("input:checked").length;
				
				$.post(
					"login.php",
					{
						login: login,
						username: username,
						password: password,
						remember: checked
					},
					function(data) { // receive response
						// fade in call to action links for players and games
						// fade out sign up section and login form
						// TODO: fade in ads
						if($(data).hasClass('success')) {
							// generate response
							$("#loginConfirm").append(data);
							
							// show response
							$("#loginConfirm").dialog({
								modal: true,
								buttons: {
										Ok: function() {
											 $(this).dialog("close");
										}
								}
							});
							
							$("#signup").fadeOut();
							$("#login").fadeOut();
							
							var players = $(jQuery('<p><a href="create-player">Create Players</a></p>'));
							var games = $(jQuery('<p><a href="create-game">Score Games</a></p>'));
							
							$("#create_players").append(players);
							players.fadeIn();
							
							$("#score_games").append(games);
							games.fadeIn();
						}else if($(data).hasClass('error')) {
							// generate response
							$("#loginConfirm").append(data);
							
							// show response
							$("#loginConfirm").dialog({
								modal: true,
								buttons: {
										Ok: function() {
											 $(this).dialog("close");
										}
								}
							});							
						}
					}
				);				
				
				// prevent default form action
				return false;
			});			
		});
    </script>
    <div id="loginConfirm" title="Login Status">
    	
    </div>
</body>
</html>